let app = getApp()
Component({
    properties: {
         id:Number
      },
      data:{
      
      }, 
      pageLifetimes: {
        show: function () {
          var that=this
          wx.request({
            url: app.globalData.siteroot,
            data: {
              do:'Distribution_getWithdrawMethodList',
              staff_id:wx.getStorageSync('staff_bind_id'),
              distribution_id:wx.getStorageSync('distribution_id')
            },
            success: function(res) {
                if(res.data.data.length==0){
                  wx.navigateTo({
                    url: '/yb_shopv2/native/all/index?type=page_addCard',
                  })
                }else{
                   if(wx.getStorageSync('choosedAccount')==''){
                    var obj = {
                      name:'applyCw',
                      cardInfo:res.data.data,
                      index:0
                     }
                    that.setData({
                      pageInfo:obj,
                      withdraw_method_id:res.data.data[0].id
                    })
                   }else{
                    var obj = {
                      name:'applyCw',
                      cardInfo:res.data.data,
                      index:wx.getStorageSync('choosedAccount').index
                     }
                    that.setData({
                      pageInfo:obj,
                      withdraw_method_id:wx.getStorageSync('choosedAccount').cardId
                    })
                   }
                 
                }
            }
          })
        }
      },
    lifetimes: {
        attached: function () {
          var that=this
          var distributionInfo=wx.getStorageSync('distributionInfo')
          var  cwAccount="可提现" + distributionInfo.available_money + "元"
          that.setData({
            getGlobalColor:app.globalData.globalColor,
            cwAccount:cwAccount
         })
        
       }
      },
    methods: {
      moneychange:function(e){
        if(typeof(e.detail.value)!='undefined')
        {
          this.setData({
            money:e.detail.value
           })
        }
      },
      apply:function(){
        var that=this
        var money=this.data.money
        var distributionInfo=wx.getStorageSync('distributionInfo')
        var  min_money=wx.getStorageSync('distribution').min_money
        if(typeof(money)!='undefined'&&money!=''&&parseInt(money)<parseInt(min_money)){
          wx.showToast({
            icon: "none",
            title: "金额小于最小提现金额"
          })
          return false
        }
        if(typeof(money)!='undefined'&&money!=''&&parseInt(money)>0)
        {
          if(parseInt(money)>parseInt(distributionInfo.available_money)){
            wx.showToast({
              icon: "none",
              title: "超过可提现金额"
            })
         }else{
          wx.request({
            url: app.globalData.siteroot,
            data: {
              do:'Distribution_applyWithdraw',
              staff_id:wx.getStorageSync('staff_bind_id'),
              distribution_id:wx.getStorageSync('distribution_id'),
              withdraw_method_id:that.data.withdraw_method_id,
              money:money
            },
            success: function(res) {
              wx.showToast({
                icon: "none",
                title: "提交成功"
              })
            }
          })
         }
        }else{
              wx.showToast({
                icon: "none",
                title: "请输入提现金额"
              })
        } 
      },
      chooseAccount:function(){
        wx.navigateTo({
          url: '/yb_shopv2/native/all/index?type=choose_account_type',
        })
      }
    }
});
